package com.yonghui;

import lombok.extern.slf4j.Slf4j;

import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;

@Slf4j
public class WeakReferenceTest {
    public static void main(String[] args) {
        log.info("=======创建弱引用=========");
        WeakReference wf=new WeakReference(new Student("张三",22));
        log.info("打印对象{}",wf.get());
        log.info("=======执行GC========");
        System.gc();
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("=======After GC");
        log.info("打印对象{}",wf.get());
    }
}
